package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.PermissionMapper;
import com.shop.pojo.Permission;
import com.shop.service.PermissionService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public Page<Permission> pageQuery(Integer pagenum, Integer pageSize, String pageQuery) {
        QueryWrapper<Permission> wrapper = new QueryWrapper<>();
        Page<Permission> page = new Page<>(pagenum,pageSize);
        if (pageQuery!=null&&pageQuery.length()>0){
            wrapper.like("name",pageQuery).or().like("keyword",pageQuery);
            page = permissionMapper.selectPage(page,wrapper);
        }else{
            page = permissionMapper.selectPage(page,null);
        }
        return page;
    }

    @Override
    public List<Permission> findAll() {
        return permissionMapper.selectList(null);
    }
}
